package com.ctg.itrdc.imageconsole.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import com.ctg.itrdc.imageconsole.util.RequestUtils;
import com.ctg.itrdc.paspsdk.pub.context.SessionContext;


public class RequestFilter implements Filter {

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {

	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
	    //每次request请求前都清除本地线程变量缓存，避免请求结束后仍然存活在多个线程中有多本地线程变量脏数据,下次请求可能会从某个存活线程中获取到脏数据
	    SessionContext.clearBaseInfo();
	    
		RequestUtils.setRequest((HttpServletRequest) request);
		chain.doFilter(request, response);

	    //每次request请求后都清除本地线程变量缓存，避免请求结束后仍然存活在多个线程中有多本地线程变量脏数据,下次请求可能会从某个存活线程中获取到脏数据
        SessionContext.clearBaseInfo();
	}

	@Override
	public void destroy() {

	}

}
